package com.example.config;

import com.alibaba.fastjson2.JSON;
import org.jetbrains.annotations.NotNull;
import xyz.lwm.lazycat.annotation.Bean;
import xyz.lwm.lazycat.web.handle.JsonMapper;

@Bean
public class FastJsonMapper implements JsonMapper {

    @NotNull
    @Override
    public byte[] toJsonBytes(@NotNull Object obj) {
        return JSON.toJSONBytes(obj);
    }

    @NotNull
    @Override
    public <T> T fromJsonBytes(@NotNull byte[] json, @NotNull Class<T> clazz) {
        return JSON.parseObject(json, clazz);
    }

}
